/* eslint-disable @typescript-eslint/no-explicit-any */
import { useRouteLoaderData } from 'react-router-dom'
import { IAuthLoader } from '../router/authLoader'
import { useStore } from '../store'
import { Button } from 'antd'

export default function AuthButton(props: any) {
  const data = useRouteLoaderData('layout') as IAuthLoader
  const role = useStore(state => state.userInfo.role)
  //不需权限的按钮、有权限标识的按钮、管理员，按钮都可用
  if (!props.auth || data.buttonList.includes(props.auth) || role === 1) {
    return <Button {...props}>{props.children}</Button>
  }
  return <></>
}
